import turtle
import datetime

def drawGap(): # 绘制数码管间隔
    turtle.penup()
    turtle.fd(5)

def drawLine(draw): # 绘制一段数码管
    drawGap()
    if draw:
        turtle.pendown()
    else:
        turtle.penup()
    turtle.fd(40)
    turtle.right(90)

def drawDigit(digit): # 根据数字绘制七段数码管
    drawLine(True) if digit in [2, 3, 4, 5, 6, 8, 9] else drawLine(False)
    drawLine(True) if digit in [0, 1, 3, 4, 5, 6, 7, 8, 9] else drawLine(False)
    drawLine(True) if digit in [0, 2, 3, 5, 6, 8, 9] else drawLine(False)
    drawLine(True) if digit in [0, 2, 6, 8] else drawLine(False)

    turtle.left(90) # 左转90度

    drawLine(True) if digit in [0, 4, 5, 6, 8, 9] else drawLine(False)
    drawLine(True) if digit in [0, 2, 3, 5, 6, 7, 8, 9] else drawLine(False)
    drawLine(True) if digit in [0, 1, 2, 3, 4, 7, 8, 9] else drawLine(False)

    turtle.left(180) # 左转180度
    turtle.penup()   # 移动到下一个数字的起始位置
    turtle.fd(20)    # 数字间的间隔

def drawDate(date_str): # 绘制日期
    turtle.pencolor("red")
    year_finished = False
    month_finished = False
    for i in date_str:
        if not year_finished and i == '-':
            turtle.write('年', font=("Arial", 18, "normal"))
            turtle.pencolor("green")
            turtle.fd(40)
            year_finished = True
        elif not month_finished and i == '-':
            turtle.write('月', font=("Arial", 18, "normal"))
            turtle.pencolor("blue")
            turtle.fd(40)
            month_finished = True
        elif i == '-':
            turtle.write('日', font=("Arial", 18, "normal"))
            turtle.pencolor("green")
            turtle.fd(40)
        else:
            drawDigit(int(i)) # 绘制数字

def main():
    turtle.speed("fastest")
    current_date = datetime.datetime.now().strftime('%Y-%m-%d')
    turtle.setup(800, 350, 200, 200)
    turtle.penup()
    turtle.fd(-300)
    turtle.pensize(10)
    drawDate(current_date)
    turtle.hideturtle()
    turtle.done()

main()
